package com.ruoyi.common.utils;

public class RedisKeyConfigure {

    private static final String WX_USER_SESSION_PREFIX = "WX:SESSION";

    public static String genWxSessionKey(String openId) {
        return Key.with(WX_USER_SESSION_PREFIX).append(openId).string();
    }

    public static String genKey(String serviceName, String... keys) {
        Key key = Key.with(serviceName);
        for (String s : keys) {
            key.append(s);
        }
        return key.string();
    }

    public static class Key {
        private StringBuilder builder;

        private Key() {
            this.builder = new StringBuilder();
        }

        private Key(String key) {
            this();
            this.builder.append(key);
        }

        public static Key with(String key) {
            return new Key(key);
        }

        public Key append(Object key) {
            builder.append(":").append(key);
            return this;
        }

        public String string() {
            return this.toString();
        }

        @Override
        public String toString() {
            return this.builder.toString();
        }
    }

}
